package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 护理等级
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController extends BaseController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<ArrayList<NursingLevelVo>> ListAll() {

        return success(nursingLevelService.ListAll());
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult addLevel(@RequestBody NursingLevelDto dto) {
        nursingLevelService.addLevel(dto);
        return success();

    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页条件查询", notes = "传入分页参数")
    public ResponseResult queryPage(
            @ApiParam(value = "护理等级名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingLevelVo> page = nursingLevelService.queryPage(name, status, pageNum, pageSize);
        return success(page);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult queryById(@PathVariable Long id) {
        NursingLevelVo vo = nursingLevelService.queryById(id);
        return success(vo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改")
    public ResponseResult updateById(@RequestBody NursingLevelDto dto) {
        int i = nursingLevelService.updateById(dto);
        return toAjax(i);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public ResponseResult deleteById(@PathVariable Long id) {
        int i = nursingLevelService.deleteById(id);
        return toAjax(i);
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "状态修改")
    public ResponseResult updateStauts(@ApiParam("用户id") @PathVariable Long id, @ApiParam("状态0-禁用 ，1-启用") @PathVariable Integer status) {
        int i = nursingLevelService.updateStauts(id, status);
        return toAjax(i);
    }

}
